package com.example.demo.design.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lyc
 * @date 2019/7/10.
 */
@Service
public class ActivityService {

    @Autowired
    private ActivityContext activityContext;

    public Object doActivity(int type){
        // 以前写法
        /*switch (type){
            case 1:return service1();//注册活动
            case 2:return service2();//抽奖活动
            case 3:return service3();//推荐活动
            case 4:return service4();//送积分活动
            case 5:return service5();//买劵 活动
            case 6:return service6();//满减 闯关 等活动
            default:throw new  RuntimeException("不存在此活动");
        }*/
        //策略模式 改写
       ActivityStrategy activityStrategy = activityContext.getStrategy(type);
       return activityStrategy.doExecution();
    }

    private Object service6() {
        return null;
    }
    private Object service5() {
        return null;
    }
    private Object service4() {
        return null;
    }

    private Object service3() {
        return null;
    }
    private Object service2() {
        return null;
    }
    private Object service1() {
        return null;
    }
}